/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ShareSetupPanel.java
 *
 * Created on May 18, 2009, 11:20:44 AM
 */

package GUI;

import java.io.File;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;

/**
 *
 * @author cs47402_08
 */
public class ShareSetupPanel extends javax.swing.JPanel {
    JFileChooser fc = new JFileChooser();
    File[] files;
    DefaultListModel lm = new DefaultListModel();

    /** Creates new form ShareSetupPanel */
    public ShareSetupPanel() {
        fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        fc.setMultiSelectionEnabled(true);
        fc.setDialogTitle("Directory Share Setup");

        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        titleLabel = new javax.swing.JLabel();
        shareChooserButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        sharedList = new javax.swing.JList();
        remSharesButton = new javax.swing.JButton();

        setPreferredSize(new java.awt.Dimension(470, 300));

        titleLabel.setFont(new java.awt.Font("Lucida Bright", 0, 18));
        titleLabel.setText("Shared Directories");

        shareChooserButton.setText("Add");
        shareChooserButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                shareChooserButtonActionPerformed(evt);
            }
        });

        jScrollPane1.setViewportView(sharedList);

        remSharesButton.setText("Remove");
        remSharesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                remSharesButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(109, 109, 109)
                        .addComponent(titleLabel))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(73, 73, 73)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(shareChooserButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(remSharesButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(66, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(titleLabel)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(shareChooserButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(remSharesButton))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(99, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void shareChooserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shareChooserButtonActionPerformed
        if (fc.showDialog(this, "Select Files") == JFileChooser.APPROVE_OPTION){
            // Save selected directory/files somewhere for sharing purposes
           files = fc.getSelectedFiles();
           for(File f : files){
               lm.addElement(f);
           }
           sharedList.setModel(lm);
        }
        else{
            System.out.println("No Selection");
        }
    }//GEN-LAST:event_shareChooserButtonActionPerformed

    private void remSharesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_remSharesButtonActionPerformed
        lm.removeElement(sharedList.getSelectedValue());
    }//GEN-LAST:event_remSharesButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton remSharesButton;
    private javax.swing.JButton shareChooserButton;
    private javax.swing.JList sharedList;
    private javax.swing.JLabel titleLabel;
    // End of variables declaration//GEN-END:variables

}
